package com.wxd.service.impl;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.wxd.bean.CarBaseInfo;
import com.wxd.bean.CarChassis;
import com.wxd.bean.CarDriver;
import com.wxd.bean.CarEngine;
import com.wxd.bean.CarImage;
import com.wxd.bean.CarVehicle;
import com.wxd.dao.AccessDB;
import com.wxd.dao.ConnectionManager;
import com.wxd.service.CarInfoService;

public class CarInfoServiceImpl implements CarInfoService {
	
	public int getCarRecourdNum() {
		String sql = "select count(*) from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if (queryForSql.size() > 0) {
			Map map = (Map) queryForSql.get(0);
			try {
				return Integer.parseInt(map.get(1).toString());
			} catch (Exception e) {
			}
		}
		return 0;
	}
	
	public JSONArray getCarBaseInfo(int startNum, int limitNum) {
		String sql = "select top "
				+ limitNum
				+ " uid,carUnit,fileNum,artificialNum,licensePlate,vehicleModel,prepareDate,vehicleType,useProperty from sys_carBasicInfo where id <= (select max(id) from (select top "
				+ (startNum + 1)
				+ " id from sys_carBasicInfo order by id desc) as t) order by id desc";

		JSONArray result = new JSONArray();
		List queryForSql = AccessDB.queryForSql(sql, true);

		for (int i = 0; i < queryForSql.size(); i++) {
			Map map = (Map) queryForSql.get(i);

			JSONObject object = new JSONObject();
			object.put("uid", map.get(1));
			object.put("carUnit", map.get(2));
			object.put("fileNum", map.get(3));
			object.put("artificialNum", map.get(4));
			object.put("licensePlate", map.get(5));
			object.put("vehicleModel", map.get(6));
			object.put("prepareDate", map.get(7));
			object.put("vehicleType", map.get(8));
			object.put("useProperty", map.get(9));
			object.put("detail", "<a href='javascript:void(0);' onclick='showDetail(\""+map.get(1)+"\")'>查看详细</a>");
			result.add(object);
		}
		return result;
	}
	public boolean saveCarBaseInfo(CarBaseInfo carBaseInfo) {
		String sql = "insert into sys_carBasicInfo(uid,carUnit,fileNum,artificialNum,licensePlate,prepareDate,vehicleModel,vehicleType,roadTransportNum,drivingLicenseNum,vehicleTechnologyLevel,fuelType,carLevelType,useProperty,acquisitionDate,commissioningDate,engineNum,turfNum,carCompany,legalPerson,legalPersonPhone,carOwner,carOwnerPhone,address) values ('"+carBaseInfo.getUid()+"','"+carBaseInfo.getCarUnit()+"','"+carBaseInfo.getFileNum()+"','"+carBaseInfo.getArtificialNum()+"','"+carBaseInfo.getLicensePlate()+"','"+carBaseInfo.getPrepareDate()+"','"+carBaseInfo.getVehicleModel()+"','"+carBaseInfo.getVehicleType()+"','"+carBaseInfo.getRoadTransportNum()+"','"+carBaseInfo.getDrivingLicenseNum()+"','"+carBaseInfo.getVehicleTechnologyLevel()+"','"+carBaseInfo.getFuelType()+"','"+carBaseInfo.getCarLevelType()+"','"+carBaseInfo.getUseProperty()+"','"+carBaseInfo.getAcquisitionDate()+"','"+carBaseInfo.getCommissioningDate()+"','"+carBaseInfo.getEngineNum()+"','"+carBaseInfo.getTurfNum()+"','"+carBaseInfo.getCarCompany()+"','"+carBaseInfo.getLegalPerson()+"','"+carBaseInfo.getLegalPersonPhone()+"','"+carBaseInfo.getCarOwner()+"','"+carBaseInfo.getCarOwnerPhone()+"','"+carBaseInfo.getAddress()+"')";
		return AccessDB.executeSql(sql, true);
	}
	
	
	public boolean editCarBaseInfo(CarBaseInfo carBaseInfo){
		String sql = "update sys_carBasicInfo set carUnit='"+carBaseInfo.getCarUnit()+"',fileNum='"+carBaseInfo.getFileNum()+"',artificialNum='"+carBaseInfo.getArtificialNum()+"',licensePlate='"+carBaseInfo.getLicensePlate()+"',prepareDate='"+carBaseInfo.getPrepareDate()+"',vehicleModel='"+carBaseInfo.getVehicleModel()+"',vehicleType='"+carBaseInfo.getVehicleType()+"',roadTransportNum='"+carBaseInfo.getRoadTransportNum()+"',drivingLicenseNum='"+carBaseInfo.getDrivingLicenseNum()+"',vehicleTechnologyLevel='"+carBaseInfo.getVehicleTechnologyLevel()+"',fuelType='"+carBaseInfo.getFuelType()+"',carLevelType='"+carBaseInfo.getCarLevelType()+"',useProperty='"+carBaseInfo.getUseProperty()+"',acquisitionDate='"+carBaseInfo.getAcquisitionDate()+"',commissioningDate='"+carBaseInfo.getCommissioningDate()+"',engineNum='"+carBaseInfo.getEngineNum()+"',turfNum='"+carBaseInfo.getTurfNum()+"',carCompany='"+carBaseInfo.getCarCompany()+"',legalPerson='"+carBaseInfo.getLegalPerson()+"',legalPersonPhone='"+carBaseInfo.getLegalPersonPhone()+"',carOwner='"+carBaseInfo.getCarOwner()+"',carOwnerPhone='"+carBaseInfo.getCarOwnerPhone()+"',address='"+carBaseInfo.getAddress()+"' where uid='"+carBaseInfo.getUid()+"'";
		return AccessDB.executeSql(sql, true);
	}
	
	public boolean saveCarImages(List<CarImage> list) {
		Connection conn = null;
		PreparedStatement pstm = null;
		String sql = "insert into sys_carImages(uid,imagePath,relativePath) values (?,?,?)";
		try {
			conn = ConnectionManager.getInstance().getConnection();
			pstm = conn.prepareStatement(sql);
			for(int i=0;i<list.size();i++){
				CarImage carImage = list.get(i);
				pstm.setString(1, carImage.getUid());
				pstm.setString(2, carImage.getImagePath());
				pstm.setString(3, carImage.getRelativePath());
				pstm.execute();
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		} catch (PropertyVetoException e) {
			e.printStackTrace();
			return false;
		}finally{
			AccessDB.close(conn, pstm, null);
		}
		return true;
	}
	
	public boolean saveCarDriver(CarDriver cd) {
		String sql = "insert into sys_driver(uid,driverName,driverPhotoPath,relativePhotoPath,idCard,address,telphone,drivingLicenceNum,drivingPermitNum,drivingPermitType,drivingPermitDate,quasiDriverYear,quasiDriverYear02) values ('"+cd.getUid()+"','"+cd.getDriverName()+"','"+cd.getDriverPhotoPath()+"','"+cd.getRelativePhotoPath()+"','"+cd.getIdCard()+"','"+cd.getAddress()+"','"+cd.getTelphone()+"','"+cd.getDrivingLicenceNum()+"','"+cd.getDrivingPermitNum()+"','"+cd.getDrivingPermitType()+"','"+cd.getDrivingPermitDate()+"','"+cd.getQuasiDriverYear()+"','"+cd.getQuasiDriverYear02()+"')";
		return AccessDB.executeSql(sql, true);
	}
	
	public boolean addVehicleInfo(CarVehicle carVehicle) {
		String sql = "insert into sys_vehicle(uid,labelType,vehicleCategory,manufacturer,driveForm,enginePosition,cabCar,cockpitSeats,deadWeight,lightWeight,topSpeed,wheelbase,wheelTrack,wheelTrack02,overallDimensions,minTurningDiameter,brakingDistance,fuelConsumption,minDistanceFromEarth,maximumGradability,fuelTankCapacity,remark) values ('"+carVehicle.getUid()+"','"+carVehicle.getLabelType()+"','"+carVehicle.getVehicleCategory()+"','"+carVehicle.getManufacturer()+"','"+carVehicle.getDriveForm()+"','"+carVehicle.getEnginePosition()+"','"+carVehicle.getCabCar()+"','"+carVehicle.getCockpitSeats()+"','"+carVehicle.getDeadWeight()+"','"+carVehicle.getLightWeight()+"','"+carVehicle.getTopSpeed()+"','"+carVehicle.getWheelbase()+"','"+carVehicle.getWheelTrack()+"','"+carVehicle.getWheelTrack02()+"','"+carVehicle.getOverallDimensions()+"','"+carVehicle.getMinTurningDiameter()+"','"+carVehicle.getBrakingDistance()+"','"+carVehicle.getFuelConsumption()+"','"+carVehicle.getMinDistanceFromEarth()+"','"+carVehicle.getMaximumGradability()+"','"+carVehicle.getFuelTankCapacity()+"','"+carVehicle.getRemark()+"')";
		return AccessDB.executeSql(sql, true);
	}
	public boolean editVehicleInfo(CarVehicle carVehicle) {
		String sql= "update sys_vehicle set labelType='"+carVehicle.getLabelType()+"',vehicleCategory='"+carVehicle.getVehicleCategory()+"',manufacturer='"+carVehicle.getManufacturer()+"',driveForm='"+carVehicle.getDriveForm()+"',enginePosition='"+carVehicle.getEnginePosition()+"',cabCar='"+carVehicle.getCabCar()+"',cockpitSeats='"+carVehicle.getCockpitSeats()+"',deadWeight='"+carVehicle.getDeadWeight()+"',lightWeight='"+carVehicle.getLightWeight()+"',topSpeed='"+carVehicle.getTopSpeed()+"',wheelbase='"+carVehicle.getWheelbase()+"',wheelTrack='"+carVehicle.getWheelTrack()+"',wheelTrack02='"+carVehicle.getWheelTrack02()+"',overallDimensions='"+carVehicle.getOverallDimensions()+"',minTurningDiameter='"+carVehicle.getMinTurningDiameter()+"',brakingDistance='"+carVehicle.getFuelConsumption()+"',fuelConsumption='"+carVehicle.getFuelConsumption()+"',minDistanceFromEarth='"+carVehicle.getMinDistanceFromEarth()+"',maximumGradability='"+carVehicle.getMaximumGradability()+"',fuelTankCapacity='"+carVehicle.getFuelTankCapacity()+"',remark='"+carVehicle.getRemark()+"' where uid='"+carVehicle.getUid()+"'";
		boolean flag =  AccessDB.executeSql(sql, true);
		if(!flag){
			return addVehicleInfo(carVehicle);
		}
		return flag;
	}
	
	public boolean addEngineInfo(CarEngine carEngine) {
		String sql = "insert into sys_engine(uid,model,form,manufacturingPlant,cylinderArrangement,displacement,boreAndStroke,compressionRatio,startupMode,workOrder,mostPowerful,maximumTorque,oilTypes,oilTypes02,remark) values ('"+carEngine.getUid()+"','"+carEngine.getModel()+"','"+carEngine.getForm()+"','"+carEngine.getManufacturingPlant()+"','"+carEngine.getCylinderArrangement()+"','"+carEngine.getDisplacement()+"','"+carEngine.getBoreAndStroke()+"','"+carEngine.getCompressionRatio()+"','"+carEngine.getStartupMode()+"','"+carEngine.getWorkOrder()+"','"+carEngine.getMostPowerful()+"','"+carEngine.getMaximumTorque()+"','"+carEngine.getOilTypes()+"','"+carEngine.getOilTypes02()+"','"+carEngine.getRemark()+"')";
		return AccessDB.executeSql(sql, true);
	}
	public boolean editEngineInfo(CarEngine carEngine) {
		String sql = "update sys_engine set model='"+carEngine.getModel()+"',form='"+carEngine.getForm()+"',manufacturingPlant='"+carEngine.getManufacturingPlant()+"',cylinderArrangement='"+carEngine.getCylinderArrangement()+"',displacement='"+carEngine.getDisplacement()+"',boreAndStroke='"+carEngine.getBoreAndStroke()+"',compressionRatio='"+carEngine.getCompressionRatio()+"',startupMode='"+carEngine.getStartupMode()+"',workOrder='"+carEngine.getWorkOrder()+"',mostPowerful='"+carEngine.getMostPowerful()+"',maximumTorque='"+carEngine.getMaximumTorque()+"',oilTypes='"+carEngine.getOilTypes()+"',oilTypes02='"+carEngine.getOilTypes02()+"',remark='"+carEngine.getRemark()+"' where uid='"+carEngine.getUid()+"'";
		boolean flag=  AccessDB.executeSql(sql, true);
		if(!flag){
			return addEngineInfo(carEngine);
		}
		return flag;
	}
	
	
	public boolean addChassisInfo(CarChassis carChassis) {
		String sql = "insert into sys_chassis(uid,clutch,transmission,shaft,mainTransmission,reductionRatio,bridgeShell,halfShaft,differential,frontSuspension,afterSuspension,tire,tireSize,wheelPressure,wheelPressure02,rim,spareTire,steeringGear,brakeFormBefore,brakingAfter,remark) values ('"+carChassis.getUid()+"','"+carChassis.getClutch()+"','"+carChassis.getTransmission()+"','"+carChassis.getShaft()+"','"+carChassis.getMainTransmission()+"','"+carChassis.getReductionRatio()+"','"+carChassis.getBridgeShell()+"','"+carChassis.getHalfShaft()+"','"+carChassis.getDifferential()+"','"+carChassis.getFrontSuspension()+"','"+carChassis.getAfterSuspension()+"','"+carChassis.getTire()+"','"+carChassis.getTireSize()+"','"+carChassis.getWheelPressure()+"','"+carChassis.getWheelPressure02()+"','"+carChassis.getRim()+"','"+carChassis.getSpareTire()+"','"+carChassis.getSteeringGear()+"','"+carChassis.getBrakeFormBefore()+"','"+carChassis.getBrakingAfter()+"','"+carChassis.getRemark()+"')";
		return AccessDB.executeSql(sql, true);
	}
	
	public boolean editChassisInfo(CarChassis carChassis) {
		String sql = "update sys_chassis set clutch='"+carChassis.getClutch()+"',transmission='"+carChassis.getTransmission()+"',shaft='"+carChassis.getShaft()+"',mainTransmission='"+carChassis.getMainTransmission()+"',reductionRatio='"+carChassis.getReductionRatio()+"',bridgeShell='"+carChassis.getBridgeShell()+"',halfShaft='"+carChassis.getHalfShaft()+"',differential='"+carChassis.getDifferential()+"',frontSuspension='"+carChassis.getFrontSuspension()+"',afterSuspension='"+carChassis.getAfterSuspension()+"',tire='"+carChassis.getTire()+"',tireSize='"+carChassis.getTireSize()+"',wheelPressure='"+carChassis.getWheelPressure()+"',wheelPressure02='"+carChassis.getWheelPressure02()+"',rim='"+carChassis.getRim()+"',spareTire='"+carChassis.getSteeringGear()+"',steeringGear='"+carChassis.getSteeringGear()+"',brakeFormBefore='"+carChassis.getBrakeFormBefore()+"',brakingAfter='"+carChassis.getRemark()+"',remark='"+carChassis.getRemark()+"' where uid='"+carChassis.getUid()+"'";
		boolean executeSql = AccessDB.executeSql(sql, true);
		if(!executeSql){
			return addChassisInfo(carChassis);
		}
		return executeSql;
	}
	
	
	public CarBaseInfo getCarBaseInfoBean(String uid) {
		CarBaseInfo carBaseInfo = new CarBaseInfo();
		String sql = "select * from sys_carBasicInfo where uid='"+uid+"'";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if(queryForSql!=null&&queryForSql.size()>0){
			Map map = (Map)queryForSql.get(0);
			carBaseInfo.setUid(map.get(2).toString());
			carBaseInfo.setCarUnit(map.get(3).toString());
			carBaseInfo.setFileNum(map.get(4).toString());
			carBaseInfo.setArtificialNum(map.get(5).toString());
			carBaseInfo.setLicensePlate(map.get(6).toString());
			carBaseInfo.setPrepareDate(map.get(7).toString());
			carBaseInfo.setVehicleModel(map.get(8).toString());
			carBaseInfo.setVehicleType(map.get(9).toString());
			carBaseInfo.setRoadTransportNum(map.get(10).toString());
			carBaseInfo.setDrivingLicenseNum(map.get(11).toString());
			carBaseInfo.setVehicleTechnologyLevel(map.get(12).toString());
			carBaseInfo.setFuelType(map.get(13).toString());
			carBaseInfo.setCarLevelType(map.get(14).toString());
			carBaseInfo.setUseProperty(map.get(15).toString());
			carBaseInfo.setAcquisitionDate(map.get(16).toString());
			carBaseInfo.setCommissioningDate(map.get(17).toString());
			carBaseInfo.setEngineNum(map.get(18).toString());
			carBaseInfo.setTurfNum(map.get(19).toString());
			carBaseInfo.setCarCompany(map.get(20).toString());
			carBaseInfo.setLegalPerson(map.get(21).toString());
			carBaseInfo.setLegalPersonPhone(map.get(22).toString());
			carBaseInfo.setCarOwner(map.get(23).toString());
			carBaseInfo.setCarOwnerPhone(map.get(24).toString());
			carBaseInfo.setAddress(map.get(25).toString());
		}
		return carBaseInfo;
	}
	public CarChassis getCarChassisBean(String uid) {
		CarChassis carChassis = new CarChassis();
		String sql = "select * from sys_chassis where uid='"+uid+"'";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if(queryForSql!=null&&queryForSql.size()>0){
			Map map = (Map)queryForSql.get(0);
			carChassis.setId(Integer.parseInt(map.get(1).toString()));
			carChassis.setUid(map.get(2).toString());
			carChassis.setClutch(map.get(3).toString());
			carChassis.setTransmission(map.get(4).toString());
			carChassis.setShaft(map.get(5).toString());
			carChassis.setMainTransmission(map.get(6).toString());
			carChassis.setReductionRatio(map.get(7).toString());
			carChassis.setBridgeShell(map.get(8).toString());
			carChassis.setHalfShaft(map.get(9).toString());
			carChassis.setDifferential(map.get(10).toString());
			carChassis.setFrontSuspension(map.get(11).toString());
			carChassis.setAfterSuspension(map.get(12).toString());
			carChassis.setTire(map.get(13).toString());
			carChassis.setTireSize(map.get(14).toString());
			carChassis.setWheelPressure(map.get(15).toString());
			carChassis.setWheelPressure02(map.get(16).toString());
			carChassis.setRim(map.get(17).toString());
			carChassis.setSpareTire(map.get(18).toString());
			carChassis.setSteeringGear(map.get(19).toString());
			carChassis.setBrakeFormBefore(map.get(20).toString());
			carChassis.setBrakingAfter(map.get(21).toString());
			carChassis.setRemark(map.get(22).toString());
		}
		return carChassis;
	}
	
	
	public CarDriver getCarDriverBeanList(String uid, String id) {
		// TODO Auto-generated method stub
		CarDriver carDriver = new CarDriver();
		String sql = "select * from sys_driver where uid='"+uid+"' and id="+id+"";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if(queryForSql!=null&&queryForSql.size()>0){
			Map map = (Map)queryForSql.get(0);
			carDriver.setId(Integer.parseInt(map.get(1).toString()));
			carDriver.setUid(map.get(2).toString());
			carDriver.setDriverName(map.get(3).toString());
			carDriver.setDriverPhotoPath(map.get(4).toString());
			carDriver.setRelativePhotoPath(map.get(5).toString());
			carDriver.setIdCard(map.get(6).toString());
			carDriver.setAddress(map.get(7).toString());
			carDriver.setTelphone(map.get(8).toString());
			carDriver.setDrivingLicenceNum(map.get(9).toString());
			carDriver.setDrivingPermitNum(map.get(10).toString());
			carDriver.setDrivingPermitType(map.get(11).toString());
			carDriver.setDrivingPermitDate(map.get(12).toString());
			carDriver.setQuasiDriverYear(map.get(13).toString());
			carDriver.setQuasiDriverYear02(map.get(14).toString());
		}
		
		return carDriver;
	}
	public List<CarDriver> getCarDriverBeanList(String uid) {
		List<CarDriver> result = new ArrayList<CarDriver>();
		String sql = "select * from sys_driver where uid='"+uid+"'";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if(queryForSql!=null&&queryForSql.size()>0){
			for(int i=0;i<queryForSql.size();i++){
				Map map = (Map)queryForSql.get(i);
				CarDriver carDriver = new CarDriver();
				carDriver.setId(Integer.parseInt(map.get(1).toString()));
				carDriver.setUid(map.get(2).toString());
				carDriver.setDriverName(map.get(3).toString());
				carDriver.setDriverPhotoPath(map.get(4).toString());
				carDriver.setRelativePhotoPath(map.get(5).toString());
				carDriver.setIdCard(map.get(6).toString());
				carDriver.setAddress(map.get(7).toString());
				carDriver.setTelphone(map.get(8).toString());
				carDriver.setDrivingLicenceNum(map.get(9).toString());
				carDriver.setDrivingPermitNum(map.get(10).toString());
				carDriver.setDrivingPermitType(map.get(11).toString());
				carDriver.setDrivingPermitDate(map.get(12).toString());
				carDriver.setQuasiDriverYear(map.get(13).toString());
				carDriver.setQuasiDriverYear02(map.get(14).toString());
				result.add(carDriver);
			}
		}
		return result;
	}
	public CarEngine getCarEngineBean(String uid) {
		CarEngine carEngine = new CarEngine();
		String sql = "select * from sys_engine where uid='"+uid+"'";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if(queryForSql!=null&&queryForSql.size()>0){
			Map map = (Map)queryForSql.get(0);
			carEngine.setId(Integer.parseInt(map.get(1).toString()));
			carEngine.setUid(map.get(2).toString());
			carEngine.setModel(map.get(3).toString());
			carEngine.setForm(map.get(4).toString());
			carEngine.setManufacturingPlant(map.get(5).toString());
			carEngine.setCylinderArrangement(map.get(6).toString());
			carEngine.setDisplacement(map.get(7).toString());
			carEngine.setBoreAndStroke(map.get(8).toString());
			carEngine.setCompressionRatio(map.get(9).toString());
			carEngine.setStartupMode(map.get(10).toString());
			carEngine.setWorkOrder(map.get(11).toString());
			carEngine.setMostPowerful(map.get(12).toString());
			carEngine.setMaximumTorque(map.get(13).toString());
			carEngine.setOilTypes(map.get(14).toString());
			carEngine.setOilTypes02(map.get(15).toString());
			carEngine.setRemark(map.get(16).toString());
			
		}
		return carEngine;
	}
	public List<CarImage> getCarImages(String uid) {
		List<CarImage> result = new ArrayList<CarImage>();
		String sql = "select id,uid,imagePath,relativePath from sys_carImages where uid='"+uid+"'";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if(queryForSql!=null&&queryForSql.size()>0){
			for(int i=0;i<queryForSql.size();i++){
				Map map = (Map)queryForSql.get(i);
				CarImage CarImage = new CarImage(Integer.parseInt(map.get(1).toString()),map.get(2).toString(),map.get(3).toString(),map.get(4).toString());
				
				result.add(CarImage);
			}
		}
		return result;
	}
	public CarVehicle getCarVehicleBean(String uid) {
		CarVehicle carVehicle = new CarVehicle();
		String sql = "select * from sys_vehicle where uid='"+uid+"'";
		List queryForSql = AccessDB.queryForSql(sql, true);
		if(queryForSql!=null&&queryForSql.size()>0){
			Map map = (Map)queryForSql.get(0);
			carVehicle.setId(Integer.parseInt(map.get(1).toString()));
			carVehicle.setUid(map.get(2).toString());
			carVehicle.setLabelType(map.get(3).toString());
			carVehicle.setVehicleCategory(map.get(4).toString());
			carVehicle.setManufacturer(map.get(5).toString());
			carVehicle.setDriveForm(map.get(6).toString());
			carVehicle.setEnginePosition(map.get(7).toString());
			carVehicle.setCabCar(map.get(8).toString());
			carVehicle.setCockpitSeats(map.get(9).toString());
			carVehicle.setDeadWeight(map.get(10).toString());
			carVehicle.setLightWeight(map.get(11).toString());
			carVehicle.setTopSpeed(map.get(12).toString());
			carVehicle.setWheelbase(map.get(13).toString());
			carVehicle.setWheelTrack(map.get(14).toString());
			carVehicle.setWheelTrack02(map.get(15).toString());
			carVehicle.setOverallDimensions(map.get(16).toString());
			carVehicle.setMinTurningDiameter(map.get(17).toString());
			carVehicle.setBrakingDistance(map.get(18).toString());
			carVehicle.setFuelConsumption(map.get(19).toString());
			carVehicle.setMinDistanceFromEarth(map.get(20).toString());
			carVehicle.setMaximumGradability(map.get(21).toString());
			carVehicle.setFuelTankCapacity(map.get(22).toString());
			carVehicle.setRemark(map.get(23).toString());
		}
		return carVehicle;
	}
	
	
	public boolean delCarInfo(String[] uid) {
		String[] sql = new String[6];
		sql[0] = "delete from sys_carBasicInfo where uid=?";
		sql[1] = "delete from sys_driver where uid=?";
		sql[2] = "delete from sys_vehicle where uid=?";
		sql[3] = "delete from sys_engine where uid=?";
		sql[4] = "delete from sys_chassis where uid=?";
		sql[5] = "delete from sys_carImages where uid=?";
		Connection conn = null;
		PreparedStatement pstm = null;
		try {
			conn =ConnectionManager.getInstance().getConnection();
			for(int i=0;i<6;i++){
				pstm = conn.prepareStatement(sql[i]);
				for(int n=0;n<uid.length;n++){
					pstm.setString(1, uid[n]);
					pstm.execute();
				}
			}
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (PropertyVetoException e) {
			e.printStackTrace();
		}finally{
			AccessDB.close(conn, pstm, null);
		}
		return false;
	}
	
	public boolean delCarDriver(String uid, String id) {
		String sql = "delete from sys_driver where uid='"+uid+"' and id="+id+"";
		return AccessDB.executeSql(sql, true);
	}
	
	public boolean delCarImage(String uid, String id) {
		String sql = "delete from sys_carImages where uid='"+uid+"' and id="+id+"";
		return AccessDB.executeSql(sql, true);
	}
	
	public boolean editCarDriverInfo(CarDriver cd) {
		String sql= "";
		if("".equals(cd.getDriverPhotoPath())){
			sql = "update sys_driver set driverName='"+cd.getDriverName()+"',idCard='"+cd.getIdCard()+"',address='"+cd.getAddress()+"',telphone='"+cd.getTelphone()+"',drivingLicenceNum='"+cd.getDrivingLicenceNum()+"',drivingPermitNum='"+cd.getDrivingPermitNum()+"',drivingPermitType='"+cd.getDrivingPermitType()+"',drivingPermitDate='"+cd.getDrivingPermitDate()+"',quasiDriverYear='"+cd.getQuasiDriverYear()+"',quasiDriverYear02='"+cd.getQuasiDriverYear02()+"' where id="+cd.getId()+" and uid='"+cd.getUid()+"'";
		}else{
			sql = "update sys_driver set driverName='"+cd.getDriverName()+"',driverPhotoPath='"+cd.getDriverPhotoPath()+"',relativePhotoPath='"+cd.getRelativePhotoPath()+"',idCard='"+cd.getIdCard()+"',address='"+cd.getAddress()+"',telphone='"+cd.getTelphone()+"',drivingLicenceNum='"+cd.getDrivingLicenceNum()+"',drivingPermitNum='"+cd.getDrivingPermitNum()+"',drivingPermitType='"+cd.getDrivingPermitType()+"',drivingPermitDate='"+cd.getDrivingPermitDate()+"',quasiDriverYear='"+cd.getQuasiDriverYear()+"',quasiDriverYear02='"+cd.getQuasiDriverYear02()+"' where id="+cd.getId()+" and uid='"+cd.getUid()+"'";
		}
		return AccessDB.executeSql(sql, true);
	}
	
	
//-------------------------以下为combo中使用的下拉选项中查找数据的方法-------------------------
	public JSONArray getComboCarUnitList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct carUnit from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboVehicleTypeList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct vehicleType from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboVehicleTechnologyLevelList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct vehicleTechnologyLevel from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboFuelTypeList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct fuelType from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboCarLevelTypeList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct carLevelType from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboUsePropertyList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct useProperty from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboCarCompanyList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct carCompany from sys_carBasicInfo";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	
	public JSONArray getComboDrivingPermitTypeList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct drivingPermitType from sys_driver";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	
	public JSONArray getComboVehicleCategoryList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct vehicleCategory from sys_vehicle";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboDriveFormList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct driveForm from sys_vehicle";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboEnginePositionList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct enginePosition from sys_vehicle";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboCabCarList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct cabCar from sys_vehicle";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	
	
	public JSONArray getComboFormList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct form from sys_engine";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	
	}
	public JSONArray getComboCylinderArrangementList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct cylinderArrangement from sys_engine";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	
	}
	public JSONArray getComboBoreAndStrokeList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct boreAndStroke from sys_engine";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	
	}
	public JSONArray getComboCompressionRatioList(){

		JSONArray result = new JSONArray();
		String sql = "select distinct compressionRatio from sys_engine";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	
	
	}
	public JSONArray getComboStartupModeList(){


		JSONArray result = new JSONArray();
		String sql = "select distinct startupMode from sys_engine";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	
	
	
	}
	public JSONArray getComboOilTypesList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct oilTypes from sys_engine";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboOilTypes02List(){
		JSONArray result = new JSONArray();
		String sql = "select distinct oilTypes02 from sys_engine";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	
	
	public JSONArray getComboClutchList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct clutch from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboTransmissionList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct transmission from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboShaftList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct shaft from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboReductionRatioList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct reductionRatio from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboFrontSuspensionList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct frontSuspension from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboAfterSuspensionList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct afterSuspension from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboTireSizeList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct tireSize from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboSpareTireList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct spareTire from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboSteeringGearList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct steeringGear from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboBrakeFormBeforeList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct brakeFormBefore from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
	public JSONArray getComboBrakingAfterList(){
		JSONArray result = new JSONArray();
		String sql = "select distinct brakingAfter from sys_chassis";
		List queryForSql = AccessDB.queryForSql(sql, true);
		for(int n=0;n<queryForSql.size();n++){
			Map map = (Map)queryForSql.get(n);
			JSONObject obj = new JSONObject();
			Object mo = map.get(1);
			if(mo==null||"".equals(mo.toString().trim())){
				continue;
			}else{
				obj.put("value", mo.toString().trim());
				result.add(obj);
			}
		}
		return result;
	}
}
